package com.web.base.wechat.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;
import com.web.base.wechat.message.WechatAutoMessageRequest;
import com.web.base.wechat.message.WechatAutoMessageResponse;
import com.web.base.wechat.model.WechatAutoMessage;

/**
 * 微信自动回复消息转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年04月27日
 */
public class WechatAutoMessageConvertor
{
	private WechatAutoMessageConvertor()
	{
	}
	
	public static WechatAutoMessage toWechatAutoMessage(WechatAutoMessageRequest request)
	{
		if (request == null)
			return null;
		
		WechatAutoMessage wechatAutoMessage = new WechatAutoMessage();
		wechatAutoMessage.setId(request.getId());
		wechatAutoMessage.setWechatId(request.getWechatId());
		wechatAutoMessage.setCode(request.getCode());
		wechatAutoMessage.setName(request.getName());
		wechatAutoMessage.setContent(request.getContent());
		wechatAutoMessage.setReplyType(request.getReplyType());
		wechatAutoMessage.setState(request.getState());
		return wechatAutoMessage;
	}
	
	public static WechatAutoMessageResponse toResponse(WechatAutoMessage wechatAutoMessage)
	{
		if (wechatAutoMessage == null)
			return null;
		
		WechatAutoMessageResponse response = new WechatAutoMessageResponse();
		response.setId(wechatAutoMessage.getId());
		response.setWechatId(wechatAutoMessage.getWechatId());
		response.setCode(wechatAutoMessage.getCode());
		response.setName(wechatAutoMessage.getName());
		response.setContent(wechatAutoMessage.getContent());
		response.setReplyType(wechatAutoMessage.getReplyType());
		response.setState(wechatAutoMessage.getState());
		
		response.setWechatName(wechatAutoMessage.getWechatName());
		return response;
	}
	
	public static List<WechatAutoMessageResponse> toResponse(List<WechatAutoMessage> list)
	{
		List<WechatAutoMessageResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (WechatAutoMessage wechatAutoMessage : list)
		{
			responseList.add(toResponse(wechatAutoMessage));
		}
		return responseList;
	}
	
	public static Map<Integer, WechatAutoMessageResponse> toResponse(Map<Integer, WechatAutoMessage> map)
	{
		Map<Integer, WechatAutoMessageResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, WechatAutoMessage> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<WechatAutoMessageResponse> toResponse(Page<WechatAutoMessage> page)
	{
		if (page == null)
			return null;
		
		Page<WechatAutoMessageResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
